﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

using SJTU.SE.RoughSet.Lib.IO;

namespace SJTU.SE.RoughSet.Lib.Data
{
    public class DecisionTable
    {
        private int[,] mSymptoms;
        private int[] mDecisions;

        // Indexer
        public int this[int i,int j]
        {
            get
            {
                return mSymptoms[i,j];
            }            
        }

        // row count of decision table
        public int ElementCount{get;private set;}

        // column count of decision table (not include decision column)
        public int SymptonCount{get;private set;}

        // all decisions
        public int[] Decisions
        {
            get
            {
                return this.mDecisions;
            }
        }

        //TODO add real constructor
        public DecisionTable()
        {
            this.ElementCount = 5;
            this.SymptonCount = 5;
            this.mSymptoms = new int[5,5];
            this.mDecisions = new int[5];
            for (int i = 0; i < 5; i++)
            {
                for (int j = 0; j < 5; j++)
                {
                    mSymptoms[i, j] = 0;
                }
                this.mDecisions[i] = i;
            }        
        }

        public DecisionTable(IDecisionTableFileInitializer initializer)
        {
            this.ElementCount = initializer.RowCount;
            this.SymptonCount = initializer.ColumnCount - 1;

            this.mSymptoms = new int[this.ElementCount, this.SymptonCount];
            this.mDecisions = new int[this.ElementCount];

            var rawData = initializer.GetRawData();

            for (int i = 0; i < this.ElementCount; i++)
            {
                for (int j = 0; j < this.SymptonCount; j++)
                {
                    this.mSymptoms[i, j] = rawData[i][j];
                }
                this.mDecisions[i] = rawData[i][SymptonCount];
            }

        }
    }
}
